package com.ddwl.data.service;

import com.ddwl.common.exception.ParamException;
import com.ddwl.data.dao.QRCodeParamsDao;
import com.ddwl.data.model.QRCodeParams;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author hemiaojun
 * @Date 2021/6/9 13:47
 */
@Service
public class QRCodeParamsService {

    @Resource
    private QRCodeParamsDao qrCodeParamsDao;

    public String getQuery(String id) {
        QRCodeParams params = qrCodeParamsDao.selectByPrimaryKey(id);
        ParamException.isNull(params);
        return params.getQuery();
    }

    public String save(String query) {
        QRCodeParams params = new QRCodeParams();
        params.setQuery(query);
        QRCodeParams exist = qrCodeParamsDao.selectOne(params);
        if (null != exist) {
            return exist.getId();
        }
        qrCodeParamsDao.insert(params);
        return params.getId();
    }
}
